﻿
using System;
using UnityEngine;

public class PlayerExp : MonoBehaviour
{
	[Header("Config")]
	[SerializeField] private PlayerStats stats;


	private void Update()
	{
		if (Input.GetKeyDown(KeyCode.X))
		{
			AddExp(300f);
		}
	}

	public void AddExp(float amount)
	{
		stats.currentExp += amount;
		while (stats.currentExp >= stats.nextLevelExp)
		{
			stats.currentExp -= stats.nextLevelExp;

			NextLevel();
		}

	}

	private void NextLevel()
	{
		stats.level++;
		float currentExpRequired = stats.nextLevelExp;
		float newNextLevelExp = Mathf.Round(currentExpRequired + stats.nextLevelExp * (stats.expMultiplier / 100f));

		stats.nextLevelExp = newNextLevelExp;

	}

}
